/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jhave.client;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import org.jdom.Element;
/**
 *
 * @author Kevin
 */
public class JHAVE_Element_Factory {
    JPanel returnedPanel;
    JPanel comboBoxPanel;
    Vector components;
    GridLayout grid;
    boolean clickingArea;
    String lastValueEntered;
    Boolean sameAlgorithm;
    


     /**
     * Finds the correct ComboBox JHAVE_Element and adds it to its proper place in the returnedPanel JPanel and components Vector.
     *
     *@param
     *@param child - Current element.
     *@param returnedPanel - The main JPanel.
     *@param components - Vector that holds added elements.
     *@param grid - Current GridLayout
     *@param comboBoxPanel - JPanel that will hold the combobox and it's labels
     *@param clickingArea - Boolean of whether or not a ClickingArea object is needed.
     *@return JHAVE_Element.
     */
    public void get_JHAVE_Element(Element child, JPanel returnedPanel, Vector components, GridLayout grid, JPanel comboBoxPanel, boolean clickingArea, String lastValueEntered, Boolean sameAlgorithm){
        String type = child.getName();
        this.comboBoxPanel = comboBoxPanel;
        this.returnedPanel = returnedPanel;
        this.components = components;
        this.grid = grid;
        this.clickingArea = clickingArea;
	this.lastValueEntered = lastValueEntered;
	this.sameAlgorithm = sameAlgorithm;

        if(type.equalsIgnoreCase("textfield")){
            Textfield_Element element = new Textfield_Element(child, this.returnedPanel, this.components);
            element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();

        }
        else if(type.equalsIgnoreCase("textarea")){
            Textarea_Element element = new Textarea_Element(child, this.returnedPanel, this.components, this.lastValueEntered, this.sameAlgorithm);
            element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
        }
        else if(type.equalsIgnoreCase("combobox")){
            Combobox_Element element = new Combobox_Element(child, this.returnedPanel, this.components, this.grid, this.comboBoxPanel);
            element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
            this.grid = element.returnGrid();
            this.comboBoxPanel = element.returnComboBoxPanel();
        }
        else if(type.equalsIgnoreCase("jvm_text_area")){
            JVM_Element element = new JVM_Element(child, this.returnedPanel, this.components);
            element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
        }
        else if(type.equalsIgnoreCase("clickingarea")){
            ClickingArea_Element element = new ClickingArea_Element(child, this.returnedPanel, this.components, -2, this.clickingArea);
            element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
            this.clickingArea = element.returnClickingArea();
        }
        else{
            //Throw error stating not a proper type
        }


    }

     /**
     * Returns returnedPanel.
     *
     *@return Returns the main JPanel.
     */
    public JPanel returnPanel(){
        return returnedPanel;
    }

     /**
     * Returns the components vector.
     *
     *@return Returns the components vector.
     */
    public Vector returnComponents(){
        return components;
    }

     /**
     * Returns GridLayout.
     *
     *@return Returns GridLayout.
     */
    public GridLayout returnGrid(){
        return grid;
    }

     /**
     * Returns ComboBox panel.
     *
     *@return Returns ComboBox JPanel.
     */
    public JPanel returnComboBoxPanel(){
        return comboBoxPanel;
    }

     /**
     * Returns ClickingArea.
     *
     *@return Returns ClickingArea.
     */
    public boolean returnClickingArea(){
        return clickingArea;
    }
}
